package com.plian.system.controller.fa.nplcancelmaintain;

import com.plian.Tools.FileTools;
import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.service.fa.nplcancelmaintain.NPLCancelMaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(value = "api/nplcancelmaintain")
public class NPLCancelMaintainController extends BaseController {
    @Autowired
    NPLCancelMaintainService nPLCancelMaintainService;

    /**
     * 新增
     *
     * @param pd
     * @return
     */
    @PostMapping(value = "/save")
    public ObjResult save(@RequestBody PageData pd) {
        return nPLCancelMaintainService.save(pd);
    }

    /**
     * 修改
     *
     * @param pd
     * @return
     */
    @PostMapping(value = "/edit")
    public ObjResult edit(@RequestBody PageData pd) {
        return nPLCancelMaintainService.edit(pd);
    }

    /**
     * 根据id查询,详情页
     *
     * @param pd
     * @return
     */
    @PostMapping(value = "/detail")
    public ObjResult detail(@RequestBody PageData pd) {
        return nPLCancelMaintainService.findbyid(pd);
    }

    /**
     * 查询列表
     *
     * @return
     */
    @PostMapping(value = "/list")
    public ListResult list(@RequestBody PageData pd) {
        return nPLCancelMaintainService.list(pd);
    }

    /**
     * 删除
     *
     * @param pd
     * @return
     */
    @PostMapping(value = "/delete")
    public ObjResult del_ids(@RequestBody PageData pd) {
        return nPLCancelMaintainService.del_ids((List<String>) pd.get("ids"));
    }

    @PostMapping(value = "/findByIds")
    public List<PageData> findByIds(List<String> formIds) {
        return nPLCancelMaintainService.findByIds(formIds);
    }

    /**
     * 打印
     */
    @GetMapping("/buildpdf/{id}")
//    @PassToken
    public ResponseEntity<FileSystemResource> buildPdf(@PathVariable String id) throws Exception {
        //return FileTools.exportPdf(staffFilesService.buildpdf(id));
        return FileTools.exportPdf(nPLCancelMaintainService.createReceptFile(id));
    }
    @PostMapping(value = "/reportList")
    public ListResult reportList(@RequestBody PageData pd){
        return nPLCancelMaintainService.reportList(pd);
    }

    /**
     * 下载doc
     */
    @GetMapping("/buildword/{id}")
//    @PassToken
    public void buildword(@PathVariable String id, HttpServletResponse response) throws Exception {
        nPLCancelMaintainService.buildword(id,response);
    }

}
